package com.xbh.management.security;

import com.xbh.common.web.core.Result;
import com.xbh.management.utils.ResponseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: management-center
 * @description: 自定义登录验证失败处理器
 * @author: 许宝华
 * @create: 2021-10-08 09:07
 */

public class LoginErrorHandler implements AuthenticationFailureHandler {

    private static Logger log = LoggerFactory.getLogger(LoginErrorHandler.class);

    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        log.info("自定义登录处理器认证失败");
        ResponseUtil.out(response, Result.result("445","验证码错误",null));
    }
}
